home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / cdrtools-1.10 / inc / avoffset.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-07  |  3.3 KB  |  110 lines

  1. /* @(#)avoffset.c    1.15 00/05/07 Copyright 1987 J. Schilling */
  2. #ifndef lint
  3. static    char sccsid[] =
  4.     "@(#)avoffset.c    1.15 00/05/07 Copyright 1987 J. Schilling";
  5. #endif
  6. /*
  7.  * This program is a tool to generate the file "avoffset.h".
  8.  * It is used by functions that trace the stack to get to the top of the stack.
  9.  *
  10.  * It generates two defines:
  11.  *    AV_OFFSET    - offset of argv relative to the main() frame pointer
  12.  *    FP_INDIR    - number of stack frames above main()
  13.  *              before encountering a NULL pointer.
  14.  *
  15.  *    Copyright (c) 1987 J. Schilling
  16.  */
  17. /*
  18.  * This program is free software; you can redistribute it and/or modify
  19.  * it under the terms of the GNU General Public License as published by
  20.  * the Free Software Foundation; either version 2, or (at your option)
  21.  * any later version.
  22.  *
  23.  * This program is distributed in the hope that it will be useful,
  24.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  26.  * GNU General Public License for more details.
  27.  *
  28.  * You should have received a copy of the GNU General Public License
  29.  * along with this program; see the file COPYING.  If not, write to
  30.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  31.  */
  32.  
  33. #include <mconfig.h>
  34. #include <stdio.h>
  35. #include <standard.h>
  36. #include <schily.h>
  37. #include <stdxlib.h>
  38. #include <signal.h>
  39.  
  40. #ifdef    NO_SCANSTACK
  41. #    ifdef    HAVE_SCANSTACK
  42. #    undef    HAVE_SCANSTACK
  43. #    endif
  44. #endif
  45.  
  46. #ifdef    HAVE_SCANSTACK
  47. #    include <stkframe.h>
  48. #endif
  49.  
  50. LOCAL    RETSIGTYPE handler __PR((int signo));
  51. EXPORT    int    main    __PR((int ac, char** av));
  52.  
  53. LOCAL    RETSIGTYPE
  54. handler(signo)
  55.     int    signo;
  56. {
  57.     fprintf(stderr, "Warning: Cannot scan stack on this environment.\n");
  58.     exit(0);
  59. }
  60.  
  61.  
  62. int main(ac, av)
  63.     int    ac;
  64.     char    **av;
  65. {
  66. #ifdef    HAVE_SCANSTACK
  67.     register struct frame *fp = (struct frame *)getfp();
  68.     register int    i = 0;
  69. #endif
  70.  
  71.     signal(SIGBUS, handler);
  72.     signal(SIGSEGV, handler);
  73.  
  74.     printf("/*\n");
  75.     printf(" * This file has been generated automatically\n");
  76.     printf(" * by %s\n", sccsid);
  77.     printf(" * do not edit by hand.\n");
  78.     printf(" *\n");
  79.     printf(" * This file includes definitions for AV_OFFSET and FP_INDIR.\n");
  80.     printf(" * FP_INDIR is the number of fp chain elements above 'main'.\n");
  81.     printf(" * AV_OFFSET is the offset of &av[0] relative to the frame pointer in 'main'.\n");
  82.     printf(" *\n");
  83.     printf(" * If getav0() does not work on a specific architecture\n");
  84.     printf(" * the program which generated this include file may dump core.\n");
  85.     printf(" * In this case, the generated include file does not include\n");
  86.     printf(" * definitions for AV_OFFSET and FP_INDIR but ends after this comment.\n");
  87.     printf(" * If AV_OFFSET or FP_INDIR are missing in this file, all programs\n");
  88.     printf(" * which use the definitions are automatically disabled.\n");
  89.     printf(" */\n");
  90.     fflush(stdout);
  91.  
  92. #ifdef    HAVE_SCANSTACK
  93.     while (fp->fr_savfp) {
  94.         fp = (struct frame *)fp->fr_savfp;
  95.         if (fp->fr_savpc == 0)
  96.             break;
  97.         i++;
  98.     }
  99.     /*
  100.      * Do not add any printf()'s before this line to allow avoffset
  101.      * to abort without printing more than the comment above.
  102.      */
  103.     fp = (struct frame *)getfp();
  104.     printf("#define    AV_OFFSET    %d\n", (int)(av-(char **)fp));
  105.     printf("#define    FP_INDIR    %d\n", i);
  106. #endif
  107.     exit(0);
  108.     return (0);    /* keep lint happy */
  109. }
  110.